package com.zhika.zishi.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zhika.zishi.R;
import com.zhika.zishi.interfaces.ChooseHomepageInterface;

/**
 * Created by shi-02 on 2015/4/13.
 */
public class ChooseHomepageView extends RelativeLayout implements View.OnClickListener{

    private  Context context;

    private TextView firstText;

    private TextView secondText;

    private ChooseHomepageInterface chooseHomepageInterface;

    public void setChooseHomepageInterface(ChooseHomepageInterface chooseHomepageInterface){
        this.chooseHomepageInterface = chooseHomepageInterface;
    }

    public ChooseHomepageView(Context context) {
        this(context, null);
    }

    public ChooseHomepageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ChooseHomepageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        this.context = context;

        initView();
    }

    private void initView(){
        View view = LayoutInflater.from(context).inflate(R.layout.choose_homepage_layout,this);
        firstText = (TextView) view.findViewById(R.id.choose_homepage_first_text);
        firstText.setOnClickListener(this);
        secondText = (TextView) view.findViewById(R.id.choose_homepage_second_text);
        secondText.setOnClickListener(this);
    }

    /**
     * 设置第一个textView的值
     * @param msg
     */
    public void setFirstText(String msg){
        firstText.setText(msg);
    }

    /**
     * 设置第二个textView的值
     * @param msg
     */
    public void setSecondText(String msg){
        secondText.setText(msg);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){

            case R.id.choose_homepage_first_text:
                setVisibility(GONE);
                chooseHomepageInterface.firstHomepageTextListener();
                break;
            case R.id.choose_homepage_second_text:
                setVisibility(GONE);
                chooseHomepageInterface.secondHomepageTextListener();
                break;
            default:
                break;
        }
    }
}
